<?php
/**
 * (exporter)
 */
namespace App\Exporter\Products;

use App\Models\Product\ProductClassify;
use App\Models\Product\ProductMixSku;
use App\Models\Product\ProductSku;
use App\Util\User;
use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\WithMapping;
class MixSkuExporter extends ExcelExporter implements WithMapping
{
    protected $fileName = '组合产品.csv';

    protected $headings = ['SKU','PartNo.','组合','组合规则','是否在售','名称','季节性','品类','采购成本','采购周期','产品状态','负责人','创建人','创建时间','状态'];

    public function map($model) : array
    {
        $data = ProductMixSku::getMixSkuPuCycleAndPuPrice($model->mix_rule);
        return [
            $model->psku_code,
            $model->part_number,
            '组合',
            $model->mix_rule,
            ProductSku::$_isSales[$model->is_sales],
            $model->psku_cn,
            ProductClassify::$_season[$model->classify->season ?? 3],
            $model->classify->title ?? '',
            numberFormat($data['unit_price']),
            $data['purchase_cycle'],
            ProductSku::$_pSkuStatus[$model->psku_status],
            User::getUsernameById($model->muser_id),
            User::getUsernameById($model->cuser_id),
            $model->created_at,
            ProductSku::$_status[$model->status],
        ];
    }

}
